package com.sllp.C71S3TsllpShop.web.back;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.sllp.C71S3TsllpShop.bean.Result;
import com.sllp.C71S3TsllpShop.bean.User;
import com.sllp.C71S3TsllpShop.biz.impl.UserBizImpl;

@Controller
public class BackUserFindAction {

	@Resource
	private UserBizImpl ubiz;
	
	
	@GetMapping("back/toUserFind.do")
	public String toUserFind(Model m) {
		m.addAttribute("userList", ubiz.findUserByCondition(null, 1, 3));
		return "back/user-find::userFind";
	}
	
	@PostMapping("back/userFind.do")
	public String userFind(User user,Model m) {
		if(user.getState() != null && user.getState() == 0) {
			user.setState(null);
		}
		m.addAttribute("userList",ubiz.findUserByCondition(user, 1, 3));
		return "back/user-find::userShowTable";
	}
	
	
	@ResponseBody
	@PostMapping("back/changeUserState.do")
	public Result changeUserState(User user,Model m) {
		return ubiz.updateUserState(user);
	}
	
	@ResponseBody
	@PostMapping("back/toShowUserDetils.do")
	public User toShowUserDetils(User user) {
		return ubiz.findUserByCondition(user,null,null).get(0);
	}
	
	@PostMapping("back/userShowToPage.do")
	public String userShowToPage(User user,int page,Model m) {
		if(user.getState() != null && user.getState() == 0) {
			user.setState(null);
		}
		m.addAttribute("userList", ubiz.findUserByCondition(user,page,3));
		return "back/user-find::userShowTable";
	}
	
}
